<form method="POST">
	
<br>ARMY: 
<select name=army>
	<option value="1" <?php if ($_POST[army] == 1) echo "selected";?>>VVS</option>
	<option value="2" <?php if ($_POST[army] == 2) echo "selected";?>>OKL</option>
</select>

		
Type:
<select name=type>
	<option value="f" <?php if ($_POST[type] == f) echo "selected";?>>Fighters</option>
	<option value="b" <?php if ($_POST[type] == b) echo "selected";?>>Bombers</option>
</select>

MaxPilots:
<input type="text" name="maxp" value="<?php echo $_POST[maxp];?>">
<br>
<br>

<input type="submit" name="dolook" value="Show me..">
	
</form>

<?php


	include "kernel.php";
	include "adw_functions.php";

	
	$army = $_POST['army'];
	$typeOf = $_POST['type'];
	$maxp = $_POST['maxp'];
	
	if ($_POST['dolook'])
	{
	    $companyes = GetAllCompanyes ();
		$planesets = GetAllPlanesets($army,$typeOf);
	
		//echo var_dump($planesets);
	
	    $acomp = GetActiveCompany ();
	    $acid = $acomp[id];
	    
	    echo "<h2>Current Company is ".$acomp['realname']."(".$acid.")</h2>";
	
	    $i=-1;
	
	    
	    foreach ($planesets as $lineid=>$company) 
	    {   	
	    	foreach ($company as $company_num=>$company_struct)
	    	{
		    	if ($company_num==$acid)	    	
		        {
					$reserv_r = mysql_query("select * from reserv where army='$army' and typeOf='$typeOf' and plane_id='".$company[$acid][planeid]."' and company_id='".$acid."'");
			
			        $reserv = mysql_fetch_assoc($reserv_r);
			
			        $N = $reserv[maxcount] - round($reserv[maxcount] * 0.25,0) - $reserv[busycount];
			
			        if ($maxp < $N * 0.40) 
			        {
			
			        	$i++;
			        	
			        	echo "<center><h3>Line #$lineid</h3></center>";
			        	echo "N (maxcount - round(maxcount * 0.25) - busycount): $N<br>";
			        	echo "N * 0.4 = ".$N * 0.4."<br>";
			        	echo "<table cellpadding=5 cellspacing=5 align=center border=1>";
				        foreach ($company as $companyid=>$planes)
			            {
			            	echo "<tr><td align=center>".$planes[planename]."</td><td>";
			            	
			            	if ($acid == $companyid)
			            		echo $reserv[busycount]." / ".$reserv[maxcount];
			            	else 
			            		echo "&nbsp;";
			            	
			            	echo "</td></tr>";	
			            }
			            echo "</table>";
			            
			        }
			        else 
			        {
			        	echo "<center><h3>Line #$lineid</h3></center>";
			        	echo "N (maxcount - round(maxcount * 0.25) - busycount): $N<br>";
			        	echo "N * 0.4 = ".$N * 0.4."<br>";
			        	
			        	echo "<table cellpadding=5 cellspacing=5 align=center border=1>";
				        foreach ($company as $companyid=>$planes)
			            {
			            	echo "<tr bgcolor=red><td align=center>".$planes[planename]."</td><td>";
			            	
			            	if ($acid == $companyid)
			            	{
			            		echo $reserv[busycount]." / ".$reserv[maxcount];
			            		echo "";
			            	}
			            	else 
			            		echo "&nbsp;";
			            	
			            	echo "</td></tr>";	
			            }
			            echo "</table>";	        	
			        }
		        }    
	    	}
	    }
	    
	}
   
?>